package com.xuan.webfinally.mapper;

import com.xuan.webfinally.entity.DefineEquip;
import com.xuan.webfinally.entity.LabelValueDTO;
import com.xuan.webfinally.entity.Pax;
import com.xuan.webfinally.entity.SlopeMonitorpoints;
import com.xuan.webfinally.entity.SlopeSensorList;
import com.xuan.webfinally.entity.pax1;
import com.xuan.webfinally.entity.SensorDataDTO;
import com.xuan.webfinally.entity.SlopeCrackData;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuan.webfinally.entity.sbtongji;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 边坡裂缝传感器监测数据表 Mapper 接口
 * </p>
 *
 * @author gyuxuan
 * @since 2025-05-18
 */
public interface SlopeCrackDataMapper extends BaseMapper<SlopeCrackData> {

    @Select("select create_time as time,crack_change from slope_crack_data where dept_id = #{deptId} order by create_time limit 5")
    List<LabelValueDTO> getListData(Long deptId);

    @Select("select crack_change,x_tilt_angle,y_tilt_angle,z_tilt_angle,xy_tilt_angle,azimuth,x_acceleration,y_acceleration,z_acceleration from slope_crack_data")
    List<DefineEquip> getDataTo();
    @Select("select x_tilt_angle,y_tilt_angle,z_tilt_angle,xy_tilt_angle from slope_crack_data where dept_id = 104")
    List<SensorDataDTO> getDeviceStatisticsNew();

    @Select("select x_tilt_angle,y_tilt_angle,z_tilt_angle,xy_tilt_angle, azimuth,x_acceleration,y_acceleration, z_acceleration from (select *,ROW_NUMBER() OVER (PARTITION BY device_sn ORDER BY update_time DESC) AS rn from slope_crack_data) t where rn = 1")
    List<sbtongji> getSbtongji();

    @Select("SELECT device_sn,monitor_id, crack_change, x_tilt_angle, y_tilt_angle, z_tilt_angle, " +
            "xy_tilt_angle, azimuth, x_acceleration, y_acceleration, z_acceleration, " +
            "create_time, update_time ,crack_change_rate " +
            "FROM (" +
            "    SELECT *, " +
            "    ROW_NUMBER() OVER (PARTITION BY monitor_id ORDER BY id DESC) AS rn " +
            "    FROM slope_crack_data " +
            "    WHERE slope_id = #{deptId} " +
            "      AND crack_change IS NOT NULL " +
            ") t " +
            "WHERE rn = 1")
    List<Pax> getPaxList(String deptId);

//    @Select("select device_sn,x_tilt_angle,y_tilt_angle,z_tilt_angle,xy_tilt_angle,azimuth,x_acceleration,y_acceleration,z_acceleration,create_time,update_time from slope_crack_data where slope_id = #{deptId} and crack_change is null")
    @Select("SELECT * FROM slope_monitorpoints WHERE slope_code = #{deptId}")
    List<SlopeMonitorpoints> getMonitorPointIds(String deptId);


    @Select("SELECT * FROM slope_sensor_list WHERE monitor_id = #{monitorId}")
    List<SlopeSensorList> getSensorList(String monitorId);

//    @Select("SELECT device_sn, crack_change, x_tilt_angle, y_tilt_angle, z_tilt_angle, " +
//            "xy_tilt_angle, azimuth, x_acceleration, y_acceleration, z_acceleration, " +
//            "create_time, update_time " +
//            "FROM (" +
//            "    SELECT *, " +
//            "    ROW_NUMBER() OVER (PARTITION BY device_sn ORDER BY id DESC) AS rn " +
//            "    FROM slope_crack_data " +
//            "    WHERE slope_id = #{deptId} " +
//            "      AND crack_change IS NOT NULL " +
//            ") t " +
//            "WHERE rn = 1")
//    Pax getPax(String slopeCode);
}
